﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Campus.Main.Basic.InsertValues;
using cpmntctrl;
using dbcntn;

namespace Campus.Main.Basic.Settings
{
    public partial class CezaEklemeForm : DefaultForm
    {
        public CezaEklemeForm()
        {
            InitializeComponent();
        }

        public CezaEklemeForm(string studentId)
        {
            InitializeComponent();
            textBox1.Text = studentId;
        }

        public override void Initialize()
        {
            aToDb=new ConnectionToDb(Helper.ConnectionString);
            aToDb.AddItem(comboBox1,"ceza");
            aToDb.AddItemDBGridView(dataGridView1,"Select a.id,a.ceza_id,a.student_id,b.description,a.date from joinceza a,ceza b where a.ceza_id=b.id and a.student_id='"+textBox1.Text+"'");
            ControlComponent.UnVisibleCells(dataGridView1,0,1);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void CezaEklemeForm_Load(object sender, EventArgs e)
        {
            Initialize();
        } 

        private void button1_Click(object sender, EventArgs e)
        {
            var a = Convert.ToString(comboBox1.SelectedValue);
            //aToDb.InsertIntoTable("joinceza","ceza_id","student_id",a,textBox1.Text);
            aToDb.InsertIntoTableCeza(textBox1.Text,a);
            Initialize();
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == -1 || e.RowIndex == -1)
            {
                return;
            }
            List<string> data = new List<string>();
            ControlComponent.AddToList(data, dataGridView1, e, 0, 1, 2, 4);
            CezaEkle f = new CezaEkle(data);
            f.FormClosed += Bind;
            f.ShowDialog();
        }
    }
}
